import threading

import pyautogui


class Robot:
    shouldReFresh = True

    @staticmethod
    def confirm():
        while True:
            print("confirm")
            location = pyautogui.locateCenterOnScreen(r"assets\confirm.png",
                                                      confidence=0.9)
            if location is not None:
                Robot.shouldReFresh = False
                pyautogui.click(location.x,
                                location.y,
                                clicks=1,
                                interval=0.2,
                                button="left")
            else:
                pass

    @staticmethod
    def reFresh():
        while Robot.shouldReFresh:
            print("刷新页面")
            location = pyautogui.locateCenterOnScreen(r"assets\reFresh.png",
                                                      confidence=0.9)
            if location is not None:
                pyautogui.click(location.x,
                                location.y,
                                clicks=1,
                                interval=0.2,
                                button="left")
            location = pyautogui.locateCenterOnScreen(r"assets\target.png",
                                                      confidence=0.9)
            if location is not None:
                pyautogui.click(location.x,
                                location.y + 140,
                                clicks=1,
                                interval=0.2,
                                button="left")


if __name__ == '__main__':
    threading.Thread(target=Robot.reFresh).start()
    Robot.confirm()
